﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Modules.quest.Display {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.geom.*;
    import Events.*;
    import flash.utils.*;
    import Display.DialogUI.*;
    import Classes.*;
    import Classes.util.*;
    import Display.*;

    public class QuestPopup extends GenericDialog {

        public static const OK:int = 1;
        public static const LATER:int = 0;
        public static const TYPE_OK:int = 0;
        public static const TYPE_YESNO:int = 1;

        public var checkBox:Class;
        private var m_window:MovieClip;
        private var m_data:Object;
        private var m_rowData:Array;
        private var m_rewardData:Array;
        private var m_imagesLoaded:int = 0;
        private var m_rowDataProcessed:Boolean = false;
        private var m_rewardContainer:Sprite;
        private var m_rewardBubble:MovieClip;
        private var m_accept:GenericButton;
        private var m_invite:GenericButton;
        private var m_skip:GenericButton;
        private var m_questCompleted:Boolean = false;
        private var m_feedData:Object = null;
        private var m_assetInfo:Object = null;
        private var m_rewardIcon:Object = null;
        private var m_npcInfo:Object = null;
        private var m_isIntro:Boolean;
        private var m_numAssetLoads:int = 4;

        public function QuestPopup(_arg1:Object=null, _arg2:Boolean=false){
            this.m_data = _arg1;
            this.m_questCompleted = _arg2;
            super("");
        }
        override protected function loadAssets():void{
            var _local1:int;
            var _local2:String;
            var _local5:XML;
            var _local6:Object;
            var _local7:Object;
            var _local8:String;
            var _local9:Object;
            var _local10:Item;
            if (!this.m_questCompleted){
                showLoadingDialog();
            };
            this.m_rowData = [];
            this.m_rewardIcon = new Object();
            _local2 = Global.getAssetURL(this.m_data.finishIcon);
            this.m_rewardIcon.image = LoadingManager.load(_local2, this.onAssetsLoaded);
            var _local3:int;
            _local1 = 0;
            while (_local1 < this.m_data.tasks.length()) {
                _local5 = this.m_data.tasks[_local1];
                _local6 = new Object();
                _local6.name = _local5.@action;
                if ((((_local5.@action == "seenQuest")) || ((_local5.@action == "popNews")))){
                    _local3++;
                } else {
                    _local6.text = ZLoc.t("Quest", ((this.m_data.name + "_task") + (_local1 + (1 - _local3))));
                    _local2 = Global.getAssetURL(_local5.@icon_url);
                    this.m_numAssetLoads++;
                    _local6.image = LoadingManager.load(_local2, this.onAssetsLoaded);
                };
                this.m_rowData.push(_local6);
                _local1++;
            };
            this.m_npcInfo = new Object();
            this.m_npcInfo.name = this.m_data.npcName;
            if (!this.m_questCompleted){
                _local2 = Global.getAssetURL(this.m_data.npcActiveUrl);
            } else {
                _local2 = Global.getAssetURL(this.m_data.npcCompleteUrl);
            };
            this.m_npcInfo.image = LoadingManager.load(_local2, this.onAssetsLoaded);
            this.m_rewardData = [];
            _local1 = 0;
            while (_local1 < (this.m_data.rewards as Array).length) {
                _local7 = this.m_data.rewards[_local1];
                if (_local7["resource"] != "xpromo"){
                    _local8 = ZLoc.t("Quest", ("reward_" + String(_local7.resource)), {amount:int(_local7.amount)});
                    if (((!((_local7.itemName == null))) && (!((_local7.itemName == ""))))){
                        _local10 = Global.gameSettings.getItemByName(_local7.itemName);
                        _local8 = _local10.localizedName;
                    };
                    if (((!((_local7.loc == ""))) && (!((_local7.loc == null))))){
                        _local8 = ZLoc.t("Dialogs", _local7.loc, {reward:_local8});
                    };
                    _local9 = new Object();
                    _local9.text = _local8;
                    _local2 = Global.getAssetURL(_local7.url);
                    this.m_numAssetLoads++;
                    _local9.image = LoadingManager.load(_local2, this.onAssetsLoaded);
                    this.m_rewardData.push(_local9);
                };
                _local1++;
            };
            this.m_assetInfo = new Object();
            Global.delayedAssets.get(DelayedAssetLoader.QUEST_ASSETS, makeAssets);
            Global.delayedAssets.get(DelayedAssetLoader.INVENTORY_ASSETS, makeAssets);
            Global.delayedAssets.get(DelayedAssetLoader.MARKET_ASSETS, makeAssets);
            var _local4:String = Global.getAssetURL(this.m_data.url);
            this.m_assetInfo.icon = LoadingManager.load(_local4, this.onAssetsLoaded);
        }
        override protected function getAssetDependencies():Array{
            var _local1:Array = [];
            _local1.push(DelayedAssetLoader.QUEST_ASSETS, DelayedAssetLoader.INVENTORY_ASSETS, DelayedAssetLoader.MARKET_ASSETS);
            return (_local1);
        }
        override protected function onAssetsLoaded(_arg1:Event=null):void{
            this.m_imagesLoaded++;
            if (this.m_imagesLoaded < this.m_numAssetLoads){
                return;
            };
            closeLoadingDialog();
            var _local2:Dictionary = new Dictionary();
            _local2["inProgressBG"] = (new m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].inProgressBG() as DisplayObject);
            _local2["completedBG"] = (new m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].completedBG() as DisplayObject);
            _local2["horizontalRule"] = (new m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].horizontalRule() as DisplayObject);
            _local2["rewardItemBG"] = (new m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].rewardItemBG() as DisplayObject);
            _local2["checkMark"] = m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].checkMark;
            _local2["subQuestField"] = m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].subQuestField;
            _local2["placeNowArrow"] = m_assetDependencies[DelayedAssetLoader.QUEST_ASSETS].placeNowArrow;
            _local2["taskInfo"] = this.m_rowData;
            _local2["rewardInfo"] = this.m_rewardData;
            _local2["rewardIcon"] = this.m_rewardIcon.image.content;
            _local2["mainIcon"] = this.m_assetInfo.icon.content;
            _local2["npcName"] = this.m_npcInfo.name;
            _local2["npcIcon"] = this.m_npcInfo.image.content;
            _local2["locObjects"] = Global.questManager.getLocObjects();
            if (this.m_questCompleted == true){
                m_jpanel = new QuestCompleteView(_local2, this.m_data);
            } else {
                m_jpanel = new QuestPopupView(_local2, this.m_data);
            };
            m_jpanel.addEventListener(Event.CLOSE, this.closePopup, false, 0, true);
            finalizeAndShow();
        }
        override public function getDialogOffset():Point{
            return (new Point(0, -5));
        }
        private function closePopup(_arg1:Event=null):void{
            var sfxVolume:* = NaN;
            var e = _arg1;
            sfxVolume = Global.gameSettings.getXML().sounds.sound.(@name == "click1").@volume;
            Sounds.play("click1");
            dispatchEvent(new GenericPopupEvent(GenericPopupEvent.SELECTED, 0));
            close();
        }
        protected function onAccept(_arg1:MouseEvent):void{
            this.closePopup();
        }
        protected function onTellFriends(_arg1:MouseEvent):void{
            this.m_accept.getButton().removeEventListener(MouseEvent.CLICK, this.onTellFriends);
            this.m_skip.getButton().removeEventListener(MouseEvent.CLICK, this.onSkip);
            this.closePopup();
        }
        protected function onSkip(_arg1:MouseEvent):void{
            this.m_accept.getButton().removeEventListener(MouseEvent.CLICK, this.onTellFriends);
            this.m_skip.getButton().removeEventListener(MouseEvent.CLICK, this.onSkip);
            this.closePopup();
        }
        override protected function getDialogStatsTrackingString():String{
            var _local1:String = ("quest_" + this.m_data.name);
            if (this.m_questCompleted){
                _local1 = (_local1 + "_complete");
            } else {
                if (this.m_isIntro){
                    _local1 = (_local1 + "_intro");
                } else {
                    _local1 = (_local1 + "_info");
                };
            };
            return (_local1);
        }
        override public function isLockable():Boolean{
            return (true);
        }

    }
}//package Modules.quest.Display 
